<style lang="less">
    @import "../../../styles/table-common.less";
</style>
<template>
    <div class="search">
        <Card>
            <Row v-show="openSearch" @keydown.enter.native="handleSearch">
                <Form ref="searchForm" :model="searchForm" inline :label-width="70">

                    <Form-item label="审核状态" prop="checkStatus">
                      <label>
                        <Select v-model="searchForm.checkStatus" placeholder="请选择" clearable style="width: 200px">
                            <Option :value="1">待审核</Option>
                            <Option :value="2">审核通过</Option>
                            <Option :value="3">审核失败</Option>
                        </Select>
                      </label>
                    </Form-item>

                    <Form-item style="margin-left:-35px;" class="br">
                        <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                        <Button @click="handleReset">重置</Button>
                        <a class="drop-down" @click="dropDown">
                            {{dropDownContent}}
                            <Icon :type="dropDownIcon"></Icon>
                        </a>
                    </Form-item>
                </Form>
            </Row>
            <Row v-show="openTip">
                <Alert show-icon>
                    已选择
                    <span class="select-count">{{selectCount}}</span> 项
                    <a class="select-clear" @click="clearSelectAll">清空</a>
                </Alert>
            </Row>
            <Row>
                <Table
                        :loading="loading"
                        border
                        :columns="columns"
                        :data="data"
                        sortable="custom"
                        @on-sort-change="changeSort"
                        @on-selection-change="showSelect"
                        ref="table"
                ></Table>
            </Row>
            <Row type="flex" justify="end" class="page">
                <Page
                        :current="searchForm.pageNumber"
                        :total="total"
                        :page-size="searchForm.pageSize"
                        @on-change="changePage"
                        @on-page-size-change="changePageSize"
                        :page-size-opts="[10,20,50]"
                        size="small"
                        show-total
                        show-elevator
                        show-sizer
                ></Page>
            </Row>
        </Card>

        <Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="500">
            <Form ref="form" :model="form" :label-width="100">

                <FormItem label="审核状态">
                    <Select v-model="checkDto.checkStatus" placeholder="请选择">
                        <Option :value="2">审核通过</Option>
                        <Option :value="3">审核失败</Option>
                    </Select>
                </FormItem>
                <FormItem label="审核原因" type="textArea">
                    <Input v-model="checkDto.checkReason" clearable style="width:100%" />
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" @click="modalVisible=false">取消</Button>
                <Button type="primary" :loading="submitLoading" @click="examCheck">提交</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import {checkExamResultConfirm, getMyExamResultConfirmCheckList} from "@/api/index";
import departmentChoose from "../../my-components/xboot/department-choose";
import checkPassword from "@/views/my-components/xboot/check-password";

export default {
        name: "user-manage",
        components: {
            departmentChoose,
            checkPassword,
        },
        data() {
            return {
                checkDto: {
                    id: '',
                    checkStatus: 2,
                    checkReason: ''
                },
                modalVisible: false,
                officeData: [],
                height: 510,
                showUser: false,
                showType: "0",
                loading: true,
                openSearch: true,
                openTip: true,
                operationLoading: false,
                loadingExport: true,
                modalExportAll: false,
                drop: false,
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                selectCount: 0,
                selectList: [],
                dataDep: [],
                searchKey: "",
                searchForm: {
                    id: "",
                    checkStatus: ''
                },
                form: {},
                columns: [
                    {
                        type: "selection",
                        width: 60,
                        align: "center",
                        fixed: "left"
                    },
                    {
                        type: "index",
                        width: 60,
                        align: "center",
                        fixed: "left"
                    },

                    {
                        title: "企业名称",
                        key: "enterpriseName",
                        minWidth: 100,
                        sortable: false,
                        fixed: "left"
                    },
                    {
                        title: "员工名字",
                        key: "employeeName",
                        minWidth: 50,
                        sortable: false,
                        fixed: "left"
                    },
                    {
                        title: "手机号",
                        key: "mobile",
                        minWidth: 100,
                        sortable: false,
                        fixed: "left",
                    },
                    {
                        title: "岗位名称",
                        key: "jobName",
                        minWidth: 50,
                        sortable: false,
                        fixed: "left",
                    },
                    {
                        title: "考场名字",
                        key: "examRoom",
                        minWidth: 10,
                        sortable: false
                    },
                    {
                        title: "监督员",
                        key: "supervisionName",
                        minWidth: 10,
                        sortable: false
                    },
                    {
                        title: "考试照",
                        key: "examSelfPic",
                        width: 120,
                        align: "center",

                        render: (h, params) => {
                            return h("Avatar", {
                                props: {
                                    src: params.row.examSelfPic
                                }
                            });
                        }
                    },

                    {
                        title: "个人照",
                        key: "personSelfPic",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            return h("PersonSelfPic", {
                                props: {
                                    src: params.row.personSelfPic
                                }
                            });
                        }
                    },
                    {
                        title: "培训详情",
                        key: "jobTrainPartName",
                        minWidth: 150,
                        sortable: false,
                    },
                    {
                        title: "审核状态",
                        key: "checkStatus",
                        align: "center",
                        width: 100,
                        render: (h, params) => {
                            if (params.row.checkStatus === 1) {
                                return h("div", [
                                    h("Badge", {
                                        props: {
                                            status: "success",
                                            text: "待审核"
                                        }
                                    })
                                ]);
                            } else if (params.row.checkStatus === 2) {
                                return h("div", [
                                    h("Badge", {
                                        props: {
                                            status: "success",
                                            text: "审核通过"
                                        }
                                    })
                                ]);
                            }else {

                                return h("div", [
                                    h("Badge", {
                                        props: {
                                            status: "error",
                                            text: "审核失败"
                                        }
                                    })
                                ]);
                            }
                        }
                    },
                    {
                        title: "审核原因",
                        key: "checkReason",
                        minWidth: 50,
                        sortable: false,
                    },

                    {
                        title: "创建时间",
                        key: "createTime",
                        sortable: true,
                        sortType: "desc",
                        width: 175
                    },
                    {
                        title: "操作",
                        key: "action",
                        width: 100,
                        align: "center",
                        fixed: "right",
                        render: (h, params) => {

                            if (params.row.checkStatus ===1 ) {

                                return h("div", [
                                    h(
                                        "Button",
                                        {
                                            props: {
                                                type: "error",
                                                size: "small"
                                            },
                                            on: {
                                                click: () => {
                                                    this.openCheck(params.row);
                                                }
                                            }
                                        },
                                        "审核"
                                    )
                                ]);
                            }

                        }
                    }
                ],
                data: [],
                exportData: [],
                total: 0,
                dictSex: this.$store.state.dict.sex
            };
        },
        methods: {
            init() {
                this.getUserList();
            },
            handleSelectDepTree(v) {
                this.form.departmentId = v;
            },
            handleSelectDep(v) {
                this.searchForm.departmentId = v;
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getUserList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getUserList();
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            getUserList() {
                // 多条件搜索用户列表
                this.loading = true;
                getMyExamResultConfirmCheckList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.code === 200) {
                        this.data = res.result.content;
                        this.total = res.result.size;
                    }else {
                        this.data = [];
                        this.total = 0;
                    }
                });
            },
            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                if (this.searchForm.username === "undefined") {
                    this.searchForm.username = "";
                }

                if (this.searchForm.mobile === "undefined") {
                    this.searchForm.mobile = "";
                }

                if (this.searchForm.officeId === "undefined") {
                    this.searchForm.officeId = "";
                }
                this.getUserList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                this.selectDep = [];
                this.searchForm.departmentId = "";
                // 重新加载数据
                this.getUserList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getUserList();
            },
            openCheck(v) {
                this.modalVisible = true;
                this.checkDto.id = v.id
            },
            examCheck(v) {
                this.$Modal.confirm({
                    title: "考试审核",
                    loading: true,
                    onOk: () => {
                        checkExamResultConfirm(this.checkDto).then(res => {
                            this.$Modal.remove();
                            if (res.success) {
                                this.$Message.success("操作成功");
                                this.getUserList();
                                this.modalVisible=false;
                            }else {
                                this.$Message.info(res.message)
                                this.getUserList();
                            }
                        });
                    }
                });
            },

            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            showSelect(e) {
                this.exportData = e;
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
        },
        mounted() {
            // 计算高度
            this.height = Number(document.documentElement.clientHeight - 230);
            this.init();
        }
    };
</script>